package dataStructure.chapter04_栈.java2;

import java.util.ArrayList;
import java.util.List;

/**
 * @author https://gitee.com/W_Jun
 * @date 2022-01-18 14:59
 * @Description 利用组合实现栈比继承更加合理。
 */
public class MyStack<E> {
    private List<E> list = new ArrayList<>();
    //private List<E> list = new LinkedList<>();//也可以用链表

    public int size() {
        return list.size();
    }

    public boolean isEmpty() {
        return list.isEmpty();
    }
    public void push(E element) {
        list.add(element);
    }

    public E pop() {
        return list.remove(list.size() - 1);
    }

    public E top() {
        return list.get(list.size() - 1);
    }
}
